package com.apesource.mallproject.controller;

import com.apesource.mallproject.pojo.AdType;
import com.apesource.mallproject.service.IAdTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

@RestController
@CrossOrigin(allowCredentials = "true", maxAge = 3600)
public class AdTypeController {
    @Autowired
    private IAdTypeService iAdTypeService;

    @RequestMapping("/allAdType")
    public List<AdType> queryAll() {
        return iAdTypeService.queryAll();
    }

    //新增
    @RequestMapping("/addAd")
    public void addAd(@RequestParam("name") String name, @RequestParam("status") String status) {
        iAdTypeService.insertAd(name, Integer.parseInt(status));
    }

    //修改
    @RequestMapping("updateAd")
    public void updateAd(@RequestParam("name") String name, @RequestParam("status") String status, @RequestParam("id") String id) {
        iAdTypeService.updateAd(name, Integer.parseInt(status), new BigInteger(id));

    }

    //删除一个
    @RequestMapping("/delAdType/{id}")
    public void delBrand(@PathVariable BigInteger id) {
        iAdTypeService.delOne(id);
    }

    //批量删除
    @RequestMapping("/batchDelAdType")
    public void batchDel(@RequestBody HashMap<String, String> idsMap) {
        String id = idsMap.get("ids");
        System.out.println(id);
        String[] ids = id.split(",");
        System.out.println(Arrays.toString(ids));
        iAdTypeService.batchDel(ids);
    }
}
